<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机显示图片</title>
</head>
<body>
    <img src="./1.jpg" width="200px" style="margin-left: 637px;" title="xxx">
    <script>
    // 1.获取图片元素
    const img=document.querySelector("img")
    // 2.获取N~M之间随机整数
    function getrandom(N,M) {
        return Math.floor(Math.random()*(M-N+1))+N
    }
    console.log(getrandom(1,4));
    const random=getrandom(1,4)
    // console.log(random);
    // 3.改变img中的src
    img.src=`./${random}.jpg`

    </script>
   
</body>
</html>